#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    //获得图标
    QIcon icon(":/image/cloud.jpg");
    //设置图标
    ui->pushButton_Icon->setIcon(icon);
    //设置图片大小
    ui->pushButton_Icon->setIconSize(QSize(71,71));

    //获得图标
    QIcon iconUp(":/image/up.jpg");
    QIcon iconDown(":/image/down.jpg");
    QIcon iconLeft(":/image/left.jpg");
    QIcon iconRight(":/image/right.jpg");
    //设置图标
    ui->pushButton_Up->setIcon(iconUp);
    ui->pushButton_Down->setIcon(iconDown);
    ui->pushButton_Left->setIcon(iconLeft);
    ui->pushButton_Right->setIcon(iconRight);
    //设置图片大小
    ui->pushButton_Up->setIconSize(QSize(70,70));
    ui->pushButton_Down->setIconSize(QSize(70,70));
    ui->pushButton_Left->setIconSize(QSize(70,70));
    ui->pushButton_Right->setIconSize(QSize(70,70));
    //设置快捷方式
    //ui->pushButton_Up->setShortcut(QKeySequence("ctrl+w"));
    //ui->pushButton_Down->setShortcut(QKeySequence("s"));
    //ui->pushButton_Left->setShortcut(QKeySequence("a"));
    //ui->pushButton_Right->setShortcut(QKeySequence("d"));

    //设置快捷方式2--枚举
    //ui->pushButton_Up->setShortcut(QKeySequence(Qt::CTRL +Qt::Key_W));
    ui->pushButton_Up->setShortcut(QKeySequence(Qt::Key_W));
    ui->pushButton_Down->setShortcut(QKeySequence(Qt::Key_S));
    ui->pushButton_Left->setShortcut(QKeySequence(Qt::Key_A));
    ui->pushButton_Right->setShortcut(QKeySequence(Qt::Key_D));


    //键盘默认支持信号连发
    //鼠标连发功能打开
    ui->pushButton_Up->setAutoRepeat(true);
    ui->pushButton_Down->setAutoRepeat(true);
    ui->pushButton_Left->setAutoRepeat(true);
    ui->pushButton_Right->setAutoRepeat(true);

}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_Up_clicked()
{
    //获得当前坐标
    QRect rect = ui->pushButton_Icon->geometry();
    //设置当前位置
    ui->pushButton_Icon->setGeometry(rect.x(),rect.y()-5,rect.width(),rect.height());
}

void Widget::on_pushButton_Down_clicked()
{
    //获得当前坐标
    QRect rect = ui->pushButton_Icon->geometry();
    //设置当前位置
    ui->pushButton_Icon->setGeometry(rect.x(),rect.y()+5,rect.width(),rect.height());
}

void Widget::on_pushButton_Right_clicked()
{
    //获得当前坐标
    QRect rect = ui->pushButton_Icon->geometry();
    //设置当前位置
    ui->pushButton_Icon->setGeometry(rect.x()+5,rect.y(),rect.width(),rect.height());
}

void Widget::on_pushButton_Left_clicked()
{
    //获得当前坐标
    QRect rect = ui->pushButton_Icon->geometry();
    //设置当前位置
    ui->pushButton_Icon->setGeometry(rect.x()-5,rect.y(),rect.width(),rect.height());
}
